//
//  SWCustomPullRefresh.swift
//  ChildStory
//
//  Created by linhan on 2016/12/17.
//  Copyright © 2016年 Aiya. All rights reserved.
//

import Foundation

protocol SWPullToRefreshAnimation:NSObjectProtocol
{
    func pullToRefreshAnimationWillStop()
    
}

extension PullToRefreshViewDelegate
{
    func pullToRefreshAnimationWillStop()
    {
        if let animator = self as? SWPullToRefreshAnimation
        {
            animator.pullToRefreshAnimationWillStop()
        }
    }
}

extension UIScrollView
{
    func willStopPullToRefresh(_ delay:Double)
    {
        if let subviews = self.pullToRefreshView?.subviews
        {
            for subview in subviews
            {
                if let animator = subview as? PullToRefreshViewDelegate
                {
                    animator.pullToRefreshAnimationWillStop()
                    setTimeout(delay, closure: {
                        self.pullToRefreshView?.loading = false
                    })
                    break
                }
            }
        }
        
    }
}



